package com.hangxiang.approval.common;


import com.hangxiang.approval.enums.ResultStatusEnum;
import com.hangxiang.approval.exception.MyException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultBean<T> implements Serializable {

    private Integer code;

    private String message;

    private T date;



    public static ResultBean success(){
        return new ResultBean(ResultStatusEnum.SUCCESS.getCode(), ResultStatusEnum.SUCCESS.getMessage(),null);
    }

    public static <T> ResultBean<T> success(Object object){
        return new ResultBean(ResultStatusEnum.SUCCESS.getCode(), ResultStatusEnum.SUCCESS.getMessage(),object);
    }


    public static <T> ResultBean<T> success(ResultStatusEnum resultStatusEnum){
        return new ResultBean(resultStatusEnum.getCode(), resultStatusEnum.getMessage(),null);
    }

    public static <T> ResultBean<T> success(ResultStatusEnum resultStatusEnum,Object onject){
        return new ResultBean(resultStatusEnum.getCode(), resultStatusEnum.getMessage(),onject);
    }

    public static <T> ResultBean<T> error(MyException ex){
        return new ResultBean(ex.getCode(), ex.getMessage(),null);
    }


}
